var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp();

Page({
    data: {
        language: "",
        amount_id: "",
        isLoadMore: !0,
        page: 1,
        total_page: 0,
        popularVideo: [],
        heightauto: "auto",
        widthauto: "auto",
        showVideo: {},
        myvideo: "",
        show: !1,
        screeheight: 0,
        minStyle: !0,
        firstcontent: !1,
        cleartime: null,
        realIndex: 0,
        kFootshow: !0,
        is_plugins: 0,
        timer: null,
        circleId: 0,
        commentsShow: !1,
        mainCommentShow: !1,
        maincomment: "",
        comment_total: 0,
        comment_page: 1,
        comment_loading: !1,
        comment_total_count: 0,
        StickCommentData: [],
        replyName: "",
        replyContent: "",
        host_comment_id: "",
        second_comment_id: "",
        is_own: !1,
        commentManagement: !1,
        replyshow: !1
    },
    onLoad: function(t) {
        this.data.myvideo = wx.createVideoContext("myvideo"), this.getinformation(), t.circleId && this.setData({
            circleId: t.circleId
        }), t.vid && this.setData({
            amount_id: t.vid
        }), t.mid && a._setMid(t.mid), t.status && this.setData({
            cardFrom: "my",
            sta: t.status
        }), t.card_id && this.setData({
            card_id: t.card_id
        }), t.from && this.setData({
            cardFrom: t.from
        }), wx.setStorageSync("circle_invitation_id", this.data.amount_id), t.page && this.setData({
            page: Number(t.page) ? Number(t.page) : 0
        }), t.page || !t.vid ? this.getData() : this.getDetail();
    },
    gofabu: function() {
        wx.navigateTo({
            url: "/packageC/video_goods/videoAgreement/videoAgreement"
        });
    },
    gomy: function() {
        wx.navigateTo({
            url: "/packageC/video_goods/myVideo/myVideo"
        });
    },
    onReady: function() {
        var t = wx.getStorageSync("langIndex");
        this.setData({
            language: t.en
        });
    },
    subMainCommentBtn: function() {
        this.setData({
            maincomment: "",
            mainCommentShow: !this.data.mainCommentShow
        });
    },
    replyBtn: function() {
        this.setData({
            replyshow: !0,
            commentManagement: !1
        });
    },
    replyshowClose: function() {
        this.setData({
            replyshow: !1
        });
    },
    commentManagementClose: function() {
        this.setData({
            commentManagement: !1
        });
    },
    replySubmitBtn: function() {
        this.data.replyContent ? (this.setData({
            replyshow: !1
        }), this.getReplyComments("reply")) : wx.showToast({
            icon: "none",
            title: "请输入回复内容",
            duration: 1500
        });
    },
    praiseBtn: function(t) {
        var e = t.currentTarget.dataset.hostcommentid, i = t.currentTarget.dataset.secondcommentid, o = t.currentTarget.dataset.index, n = t.currentTarget.dataset.chilindex;
        if (1 == t.currentTarget.dataset.ispraise) return a.tips("你已赞过该贴");
        this.getPraiseData(e, i, o, n);
    },
    getPraiseData: function(e, i, o, n) {
        var s = this, d = {}, r = a.getNetAddresss("plugin.circle.frontend.circle-invitation.comment-like");
        d.invitation_id = this.data.amount_id, d.comment_id = e && i ? i : e, a._postNetWork({
            url: r,
            showToastIn: !1,
            data: d,
            success: function(d) {
                var r, c, l = d.data;
                (a.tips(l.msg), 1 == l.result) && (e && i ? s.setData((t(r = {}, "StickCommentData.[" + o + "].has_many_comment[" + n + "].is_like", 1), 
                t(r, "StickCommentData.[" + o + "].has_many_comment[" + n + "].link_count", s.data.StickCommentData[o].has_many_comment[n].link_count ? s.data.StickCommentData[o].has_many_comment[n].link_count + 1 : 1), 
                r)) : s.setData((t(c = {}, "StickCommentData[" + o + "].is_like", 1), t(c, "StickCommentData[" + o + "].link_count", s.data.StickCommentData[o].link_count ? s.data.StickCommentData[o].link_count + 1 : 1), 
                c)));
            },
            fail: function(t) {}
        });
    },
    delBtn: function() {
        this.data.host_comment_id && this.data.second_comment_id ? this.setData({
            commend_id: this.data.second_comment_id
        }) : this.setData({
            commend_id: this.data.host_comment_id
        }), this.setData({
            commentManagement: !1
        }), this.delReply();
    },
    delReply: function() {
        var t = this, e = {}, i = a.getNetAddresss("plugin.circle.frontend.circle-invitation.delete-comment");
        e.comment_id = this.data.commend_id, a._postNetWork({
            url: i,
            showToastIn: !1,
            data: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.getStickComment(), wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    subMainBtn: function() {
        this.data.maincomment ? (this.setData({
            mainCommentShow: !1
        }), this.getReplyComments("main")) : wx.showToast({
            icon: "none",
            title: "请输入你的精彩评论",
            duration: 1500
        });
    },
    getReplyComments: function(t) {
        var e = this, i = {}, o = a.getNetAddresss("plugin.circle.frontend.circle-invitation.comment");
        i.invitation_id = e.data.amount_id, i.comment = "main" == t ? e.data.maincomment : e.data.replyContent, 
        "reply" == t && (this.data.host_comment_id && (i.parent_id = this.data.host_comment_id), 
        this.data.second_comment_id && (i.subordinate_id = this.data.second_comment_id)), 
        a._postNetWork({
            url: o,
            showToastIn: !1,
            data: i,
            success: function(t) {
                var a = t.data;
                1 == a.result ? (e.getStickComment(), wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                })) : wx.showToast({
                    icon: "none",
                    title: a.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    getStickComment: function() {
        var t = this;
        this.setData({
            comment_page: 1,
            comment_total: 0
        });
        var e = {
            invitation_id: this.data.amount_id
        }, i = a.getNetAddresss("plugin.circle.frontend.circle-invitation.get-comment-list");
        a._postNetWork({
            url: i,
            showToastIn: !1,
            data: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? t.setData({
                    comment_total: e.data.last_page,
                    StickCommentData: e.data.data,
                    comment_total_count: e.data.total
                }) : wx.showToast({
                    icon: "none",
                    title: e.msg,
                    duration: 1500
                });
            },
            fail: function(t) {}
        });
    },
    replyCommentsBtn: function(t) {
        var a = t.currentTarget.dataset.hostcommentid, e = t.currentTarget.dataset.secondcommentid, i = t.currentTarget.dataset.uname, o = t.currentTarget.dataset.content, n = t.currentTarget.dataset.isown;
        this.setData({
            host_comment_id: a,
            second_comment_id: e,
            replyContent: "",
            replyName: i,
            replyshowcontent: o
        }), console.log(this.data.replyContent), 1 == n ? this.setData({
            is_own: !0
        }) : this.setData({
            is_own: !1
        }), this.setData({
            commentManagement: !0
        });
    },
    onShow: function() {},
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    aaaa: function() {
        console.log("执行加载更多");
    },
    getMoreStickComment: function() {
        var t = this;
        console.log("执行加载更多");
        var e = {
            invitation_id: this.data.amount_id
        };
        if (console.log("执行加载更多", this.data.comment_loading), !this.data.comment_loading) {
            this.setData({
                comment_loading: !0
            });
            var i = a.getNetAddresss("plugin.circle.frontend.circle-invitation.get-comment-list");
            this.data.comment_page >= this.data.comment_total ? this.setData({
                loading: !0
            }) : (this.setData({
                comment_page: this.data.comment_page + 1
            }), e.page = this.data.comment_page, a._postNetWork({
                url: i,
                showToastIn: !1,
                data: e,
                success: function(a) {
                    var e = a.data;
                    if (1 == e.result) {
                        var i = e.data.data;
                        t.setData({
                            StickCommentData: t.data.StickCommentData.concat(i),
                            comment_loading: !1
                        });
                    } else t.setData({
                        comment_page: t.data.comment_page - 1,
                        comment_loading: !1
                    });
                },
                fail: function(t) {}
            }));
        }
    },
    onReachBottom: function() {},
    onShareTimeline: function() {
        var t = wx.getStorageSync("yz_uid"), a = "";
        t && (a = t);
        var e = {}, i = "";
        return this.data.popularVideo[this.data.realIndex] && this.data.popularVideo[this.data.realIndex].img && (i = this.data.popularVideo[this.data.realIndex].img), 
        e = {
            title: this.data.showVideo.title ? this.data.showVideo.title : "",
            query: "vid=" + this.data.amount_id + "&page=" + this.page + "&mid=" + a + "&circleId=" + this.data.circleId
        }, i && (e.imageUrl = i), console.log(e), e;
    },
    onShareAppMessage: function(t) {
        console.log(t);
        var a = wx.getStorageSync("yz_uid"), e = "";
        a && (e = a);
        var i = {}, o = "";
        return this.data.popularVideo[this.data.realIndex] && this.data.popularVideo[this.data.realIndex].img && (o = this.data.popularVideo[this.data.realIndex].img), 
        i = {
            title: this.data.showVideo.title ? this.data.showVideo.title : "",
            path: "/packageH/circleCommunity/videoDetails/videoDetails?vid=" + this.data.amount_id + "&page=" + this.data.page + "&mid=" + e + "&circleId=" + this.data.circleId
        }, o && (i.imageUrl = o), i;
    },
    getDetail: function() {
        var t = this, e = a.getNetAddresss("plugin.video-share.frontend.video.getVideoGoods");
        e += "&video_goods_id=" + this.data.amount_id, a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                1 == e.result ? (t.setData({
                    showVideo: e.data.video_goods
                }), t.getData(!0)) : wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getData: function(t) {
        var e, i = this;
        "card" == this.data.cardFrom ? (e = a.getNetAddresss("plugin.business-card.frontend.controllers.card.paging.videos"), 
        e += "&page=" + this.data.page, e += "&card_id=" + this.data.card_id) : "my" == i.data.cardFrom ? (e = a.getNetAddresss("plugin.video-share.frontend.video.my-video"), 
        e += "&page=" + this.data.page, e += "&vid=" + this.data.amount_id, e += "&status=" + this.data.sta) : (e = a.getNetAddresss("plugin.circle.frontend.circle-invitation.get-circle-invitation-list"), 
        e += "&page=" + this.data.page, e += "&invitation_status=2", e += "&circle_id=" + this.data.circleId), 
        a._getNetWork({
            url: e,
            success: function(a) {
                var e = a.data;
                if (1 == e.result) {
                    i.data.isLoadMore = !0, i.setData({
                        is_plugins: e.data.is_plugins
                    });
                    try {
                        i.setData({
                            is_plugins: e.data.is_plugins
                        });
                    } catch (t) {
                        console.log(t);
                    }
                    try {
                        if (e.data.video_redpack && 1 === e.data.video_redpack.is_open) {
                            console.log("短视频红包================"), i.setData({
                                is_openRedpack: !0,
                                openRedpackData: e.data.video_redpack.data
                            });
                            for (var o = 0; o < i.data.openRedpackData.length; o++) "1" === i.data.openRedpackData[o].view_time_open_state && i.data.openRedpackTimes.push(i.data.openRedpackData[o].view_time_data);
                            i.data.openRedpackTimes = i.data.openRedpackTimes.sort(function(t, a) {
                                return t - a;
                            }), console.log("短视频红包累计观看时长数组", i.data.openRedpackTimes);
                        }
                    } catch (t) {
                        console.log("error", t);
                    }
                    if ("card" == i.data.cardFrom) {
                        i.data.total_page = e.data.last_page, i.data.total_page || (i.data.total_page = 0), 
                        i.setData({
                            popularVideo: e.data.data
                        });
                        var n = e.data.data;
                        if (i.data.amount_id) {
                            for (var s = 0; s < e.data.data.length; s++) if (e.data.data[s].id == i.data.amount_id) return i.setData({
                                showVideo: e.data.data[s]
                            }), n.splice(0, s), i.setData({
                                popularVideo: n
                            }), wx.setNavigationBarTitle({
                                title: i.data.showVideo.title
                            }), i.setData({
                                firstcontent: !0
                            }), void i.clickSwiperbtn(0);
                            wx.setNavigationBarTitle({
                                title: i.data.showVideo.title
                            });
                        } else i.setData({
                            showVideo: i.data.popularVideo[0]
                        }), i.clickSwiperbtn(0);
                    } else if ("my" == i.data.cardFrom) {
                        i.data.total_page = e.data.video.last_page, i.data.total_page || (i.data.total_page = 0), 
                        i.setData({
                            popularVideo: e.data.video.data
                        });
                        var d = e.data.video.data;
                        if (i.data.amount_id) {
                            for (var r = 0; r < e.data.video.data.length; r++) if (e.data.video.data[r].id == i.data.amount_id) return i.setData({
                                showVideo: e.data.video.data[r]
                            }), d.splice(0, r), i.setData({
                                popularVideo: d
                            }), wx.setNavigationBarTitle({
                                title: i.data.showVideo.title
                            }), i.setData({
                                firstcontent: !0
                            }), void i.clickSwiperbtn(0);
                            wx.setNavigationBarTitle({
                                title: i.data.showVideo.title
                            });
                        } else i.setData({
                            showVideo: i.data.popularVideo[0]
                        }), i.clickSwiperbtn(0);
                    } else {
                        i.data.total_page = e.data.last_page, i.data.total_page || (i.data.total_page = 0), 
                        i.setData({
                            popularVideo: e.data.data
                        });
                        var c = e.data.data;
                        if (t) {
                            if (i.data.amount_id) {
                                for (var l = 0; l < e.data.list.data.length; l++) if (e.data.list.data[l].id == i.data.amount_id) {
                                    c.splice(l, 1);
                                    break;
                                }
                                c.unshift(i.data.showVideo), i.setData({
                                    popularVideo: c
                                }), wx.setNavigationBarTitle({
                                    title: i.data.showVideo.title
                                }), i.clickSwiperbtn(0);
                            }
                        } else if (i.data.amount_id) {
                            for (var m = 0; m < e.data.data.length; m++) if (e.data.data[m].id == i.data.amount_id) return i.setData({
                                showVideo: e.data.data[m]
                            }), c.splice(0, m), i.setData({
                                popularVideo: c
                            }), wx.setNavigationBarTitle({
                                title: i.data.showVideo.title
                            }), i.setData({
                                firstcontent: !0
                            }), void i.clickSwiperbtn(0);
                            wx.setNavigationBarTitle({
                                title: i.data.showVideo.title
                            });
                        } else i.setData({
                            showVideo: i.data.popularVideo[0]
                        }), i.clickSwiperbtn(0);
                    }
                    i.setData({
                        firstcontent: !0
                    });
                } else wx.showToast({
                    title: e.msg,
                    icon: "none",
                    duration: 1500
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    getinformation: function() {
        try {
            var t = wx.getSystemInfoSync(), a = t.windowHeight, e = t.windowWidth;
            this.setData({
                heightauto: a + "px",
                widthauto: e + "px"
            }), this.data.screeheight = a;
        } catch (t) {}
    },
    clickSwiperbtn: function(t) {
        console.log(t);
        var a = 0;
        a = t.currentTarget ? t.currentTarget.dataset.index : t, this.clickSwiper(a);
    },
    clickSwiper: function(a) {
        var e = a;
        if (console.log("zhixing"), this.data.popularVideo[e].show && this.data.amount_id === this.data.popularVideo[e].id) return this.setData(t({
            show: !1
        }, "popularVideo[" + e + "].show", !1)), void this.data.myvideo.pause();
        this.judgmentpic(e), this.setData(t({
            show: !0,
            amount_id: this.data.popularVideo[e].id
        }, "popularVideo[" + e + "].show", !0)), this.data.logID = 0, this.data.myvideo.play(), 
        this.getStickComment();
    },
    popularVideoChange: function(t) {
        clearTimeout(this.data.cleartime);
        var a = t.detail.current;
        this.data.realIndex = a, this.data.AnswerID = 0, this.data.cumulativeDuration = parseInt(this.data.cumulativeDuration + this.data.currentDuration), 
        this.data.currentDuration = 0, this.judgmentpic_2(a);
    },
    judgmentpic_2: function(t) {
        var a = t, e = this;
        try {
            if (e.data.popularVideo[a] && e.data.popularVideo[a].cover) {
                var i = wx.createSelectorQuery();
                i.select("#pic_" + a).boundingClientRect(), i.exec(function(t) {
                    var i = e.data.screeheight;
                    t[0] && t[0].height ? t[0].height > Math.ceil(i * (7 / 8)) ? (e.setData({
                        minStyle: !1
                    }), e.getvideomessage(a)) : (e.setData({
                        minStyle: !0
                    }), e.getvideomessage(a)) : (e.setData({
                        minStyle: !0
                    }), e.getvideomessage(a));
                });
            } else e.setData({
                minStyle: !0
            }), e.getvideomessage(a);
        } catch (t) {
            e.setData({
                minStyle: !0
            }), e.getvideomessage(a);
        }
    },
    getvideomessage: function(a) {
        var e, i, o = this;
        (a == o.data.popularVideo.length - 2 && o.getMoreData(), this.data.myvideo.pause(), 
        o.setData({
            show: !1,
            showVideo: o.data.popularVideo[a]
        }), 0 === a) ? this.setData((t(e = {}, "popularVideo[" + a + "].show", !1), t(e, "popularVideo[" + (a + 1) + "].show", !1), 
        e)) : (this.setData((t(i = {}, "popularVideo[" + (a - 1) + "].show", !1), t(i, "popularVideo[" + a + "].show", !1), 
        i)), o.data.popularVideo[a + 1] && this.setData(t({}, "popularVideo[" + (a + 1) + "].show", !1)));
        wx.setNavigationBarTitle({
            title: o.data.showVideo.title
        }), wx.setStorageSync("circle_invitation_id", this.data.showVideo.id), this.data.cleartime = setTimeout(function() {
            o.clickSwiper(a);
        }, 300);
    },
    getMoreData: function() {
        var t = this;
        if (t.data.isLoadMore = !1, !(this.data.page >= this.data.total_page)) {
            this.data.page = this.data.page + 1;
            var e = a.getNetAddresss("plugin.circle.frontend.circle-invitation.get-circle-invitation-list");
            a._getNetWork({
                url: e,
                data: {
                    page: this.data.page
                },
                success: function(a) {
                    t.data.isLoadMore = !0;
                    var e = a.data;
                    if (1 == e.result) {
                        var i = e.data.list.data;
                        t.setData({
                            popularVideo: t.data.popularVideo.concat(i)
                        });
                    } else t.data.page = t.data.page - 1, t.data.isLoadMore = !1;
                },
                fail: function(t) {
                    console.log(t);
                }
            });
        }
    },
    chooseUser: function(t) {
        var a = t.currentTarget.dataset.item;
        0 != a.member.business_card && wx.navigateTo({
            url: "/packageB/member/business_card/BusinessCard/BusinessCard?card_id=" + a.member.business_card + "&mark=card"
        });
    },
    toggleLike: function(e) {
        var i = e.currentTarget.dataset.index;
        0 == this.data.popularVideo[i].is_like && this.setData(t({}, "popularVideo[" + i + "].link_count", this.data.popularVideo[i].link_count + 1)), 
        this.setData(t({}, "popularVideo[" + i + "].is_like", !0));
        var o = a.getNetAddresss("plugin.circle.frontend.circle-invitation.like"), n = {
            invitation_id: this.data.amount_id
        };
        a._postNetWork({
            url: o,
            showToastIn: !1,
            data: n,
            success: function(t) {
                var e = t.data;
                a.tips(e.msg);
            },
            fail: function(t) {}
        });
    },
    shareVideo: function() {},
    close: function() {
        this.setData({
            showShare: !1
        });
    },
    openComments: function() {
        this.setData({
            commentsShow: !this.data.commentsShow
        });
    },
    toGood: function(t) {
        var a = t.currentTarget.dataset.item;
        wx.navigateTo({
            url: "/packageA/detail_v2/detail_v2?id=" + a.goods_id + "&circle_invitation_id=" + a.id
        });
    },
    judgmentpic: function(t) {
        var a = t, e = this, i = wx.createSelectorQuery();
        i.select("#pic_" + a).boundingClientRect(), i.exec(function(t) {
            var a = e.data.screeheight;
            t[0].height > Math.ceil(a * (7 / 8)) ? e.setData({
                minStyle: !1
            }) : e.setData({
                minStyle: !0
            });
        });
    },
    endedPlay: function() {
        console.log("播放结束");
    },
    onPlaying: function() {
        console.log("onPlaying=================");
    }
});